473,463 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Incremental Compression

Hey.

I have a problem in some network code. I want to send my packets compressed,
but I don't want to compress each packet separately (via .encode('zlib') or
such) but rather I'd like to compress it with regard to the history of the
compression stream. If I use zlib.compressobj and flush it to get the
packet data, I cannot continue to compress with that stream.

I cannot wait until the end of the stream and then flush, because I need to
flush after every packet.

Another capability I require is to be able to copy the compression stream.
i.e: To be able to create multiple continuations of the same compression
stream. Something like:

a = compressobj()
pre_x = a.copy()
x = a.compress('my_packet1')
# send x
# x was not acked yet, so we must send another packet via the pre_x
compressor
y = pre_x.compress('my_packet2')

Is there a compression object that can do all this?
Mar 25 '06 #1
2 2234
On Sat, 2006-03-25 at 03:08 +0200, Eyal Lotem wrote:
Hey.

I have a problem in some network code. I want to send my packets compressed,
but I don't want to compress each packet separately (via .encode('zlib') or
such) but rather I'd like to compress it with regard to the history of the
compression stream. If I use zlib.compressobj and flush it to get the
packet data, I cannot continue to compress with that stream.
Yes, you can.

Help on built-in function flush:

flush(...)
flush( [mode] ) -- Return a string containing any remaining
compressed data.
mode can be one of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH,
Z_FINISH; the
default value used when mode is not specified is Z_FINISH.
If mode == Z_FINISH, the compressor object can no longer be used
after
calling the flush() method. Otherwise, more data can still be
compressed.

you want to call

mycompressor.flush( zlib.Z_SYNC_FLUSH )

The difference between the flushes is this:

1. Z_SYNC_FLUSH. This basically send enough data so that the receiver
will get everything you put in. This does decerase your compression
ratio (however, in weird case when I last played with it, it helped.)

2. Z_FULL_FLUSH. This sends enough data so that the receiver will get
everything you put in. This also wipes the compressors statistics, so
the when you pick up where you left of, the compressor will compress
about as well as if you had just started, you are wiping its memory of
what it saw in the past.

3. Z_FINISH. This is the default action, this is what is killing you.

Good luck - Adam DePrince

I cannot wait until the end of the stream and then flush, because I need to
flush after every packet.

Another capability I require is to be able to copy the compression stream.
i.e: To be able to create multiple continuations of the same compression
stream. Something like:

a = compressobj()
pre_x = a.copy()
x = a.compress('my_packet1')
# send x
# x was not acked yet, so we must send another packet via the pre_x
compressor
y = pre_x.compress('my_packet2')

Is there a compression object that can do all this?

Ahh, you are trying to "pretune" the compressor before sending a little
bit ... I think C-zlib does this, but I don't know for sure.

- Adam DePrince

Mar 25 '06 #2
Adam DePrince wrote:
On Sat, 2006-03-25 at 03:08 +0200, Eyal Lotem wrote:
Hey.

I have a problem in some network code. I want to send my packets
compressed, but I don't want to compress each packet separately (via
.encode('zlib') or such) but rather I'd like to compress it with regard
to the history of the
compression stream. If I use zlib.compressobj and flush it to get the
packet data, I cannot continue to compress with that stream.
Yes, you can.

Help on built-in function flush:

flush(...)
flush( [mode] ) -- Return a string containing any remaining
compressed data.
mode can be one of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH,
Z_FINISH; the
default value used when mode is not specified is Z_FINISH.
If mode == Z_FINISH, the compressor object can no longer be used
after
calling the flush() method. Otherwise, more data can still be
compressed.

you want to call

mycompressor.flush( zlib.Z_SYNC_FLUSH )

The difference between the flushes is this:

1. Z_SYNC_FLUSH. This basically send enough data so that the receiver
will get everything you put in. This does decerase your compression
ratio (however, in weird case when I last played with it, it helped.)

2. Z_FULL_FLUSH. This sends enough data so that the receiver will get
everything you put in. This also wipes the compressors statistics, so
the when you pick up where you left of, the compressor will compress
about as well as if you had just started, you are wiping its memory of
what it saw in the past.

3. Z_FINISH. This is the default action, this is what is killing you.

Good luck - Adam DePrince


Thanks! That really helps.

I cannot wait until the end of the stream and then flush, because I need
to flush after every packet.

Another capability I require is to be able to copy the compression
stream. i.e: To be able to create multiple continuations of the same
compression stream. Something like:

a = compressobj()
pre_x = a.copy()
x = a.compress('my_packet1')
# send x
# x was not acked yet, so we must send another packet via the pre_x
compressor
y = pre_x.compress('my_packet2')

Is there a compression object that can do all this?

Ahh, you are trying to "pretune" the compressor before sending a little
bit ... I think C-zlib does this, but I don't know for sure.


Yeah, but I don't need a powerful tuning, just a means to copy the
compressor's state. I guess I'll need to write some C for this.

Thanks again!

- Adam DePrince


Mar 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bangalore | last post by:
Hi In reversing string usring recursive function, i found problems in using incremental postfix , and incremental prefix 1 void rev(char*); 2 void main() 3 { 4 char s="STRING"; 5 ...
1
by: jane | last post by:
HI, I had a question on incremental backup. We had an incremental backup every weekend. We did full backup every other week. That is one week incremental + full , the other week is...
1
by: Jimmy Chen | last post by:
Recently I've done a db2 backup and restore/recovery, but the process for recovering the database was different than what I thought to be. here is what I did: DB2 is set in online mode -...
3
by: apple | last post by:
UDB v8 fp 6a on AIX 5.1.0.0 Below is a manual incremental recover from compressed backup datasets. With external compress backup datasets, can it be coded to do an automatic incremental recover?...
0
by: Willem | last post by:
Based on MK's TSI_SOON (http://www.trigeminal.com/)I've created a nifty little procedure that - whenever you compact you db you get an incremental backup copy. Given that you have a table with...
6
by: Rudy Ray Moore | last post by:
I work with a multi-project workspace. One project (the "startup" project) has a "Configuration Type" of "Application (.exe)". The other 40 projects have a "Configuration Type" of "Static Library...
3
by: Alex Shturm | last post by:
Hi, I am trying to activate incremental link using VC7 (.NET 2003) on a pretty big project (executable size is more than 100Mb, and it gets linked from several dozen of libraries and object...
6
by: Raj | last post by:
How can we do an online restore of a tablespace using the incremental backup's? we are on a partitioned database... Also, how could we use backup copy made by the load (using the copy to option...
8
by: Bern McCarty | last post by:
We have a large mixed dll that I can never seem to get to link incrementally. Below is the console output. For simplicity I've eliminated some stuff that we normally do when we really link this...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.